package com.spzx.order.controller;




import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spzx.common.core.domain.R;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import com.spzx.common.security.annotation.InnerAuth;
import com.spzx.common.security.annotation.RequiresLogin;
import com.spzx.order.domain.OrderForm;
import com.spzx.order.domain.OrderInfo;
import com.spzx.order.service.IOrderInfoService;
import io.swagger.v3.oas.annotations.Operation;

import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Tag(name = "订单接口管理")
@RestController
@RequestMapping("/orderInfo")
public class OrderInfoController extends BaseController {

    @Autowired
    private IOrderInfoService orderInfoService;

    //跳转结算页面接口
    @Operation(summary = "订单结算")
    @RequiresLogin
    @GetMapping("/trade")
    public AjaxResult orderTradeData() {
        return success(orderInfoService.orderTradeData());
    }

    //下单接口
    @Operation(summary = "用户提交订单")
    @RequiresLogin
    @PostMapping("/submitOrder")
    public AjaxResult submitOrder(@RequestBody OrderForm orderForm) {
        Long orderId = orderInfoService.submitOrder(orderForm);
        return success(orderId);
    }

    @Operation(summary = "获取订单信息")
    @RequiresLogin
    @GetMapping("getOrderInfo/{orderId}")
    public AjaxResult getOrderInfo(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderInfoService.getById(orderId);
        return success(orderInfo);
    }

    //根据订单编号查询订单数据
    @Operation(summary = "根据订单号获取订单信息")
    @InnerAuth
    @GetMapping("getByOrderNo/{orderNo}")
    public R<OrderInfo> getByOrderNo(@PathVariable String orderNo) {
        OrderInfo orderInfo = orderInfoService.getByOrderNo(orderNo);
        return R.ok(orderInfo);
    }

    @Operation(summary = "获取全部订单信息")
    @RequiresLogin
    @GetMapping("userOrderInfoList/{current}/{size}")
    public R<IPage<OrderInfo>> getOrderInfoList(
            @PathVariable Integer current,
            @PathVariable Integer size,
            @RequestParam(required = false, defaultValue = "") Integer orderStatus) {

        Page<OrderInfo> orderInfoPage = orderInfoService.pageOrderInfoList(new Page<OrderInfo>(current, size), orderStatus);
        return R.K(orderInfoPage,666,"999");
    }
}
